package com.basic.modules.nykf.controller;


import com.basic.common.utils.PageUtils;
import com.basic.common.utils.ParamsModel;
import com.basic.common.utils.R;
import com.basic.modules.nykf.entity.CustomerComplaintRegistrationEntity;
import com.basic.modules.nykf.service.CustomerComplaintRegistrationService;
import com.basic.modules.nykf.service.DictDetailService;
import com.basic.modules.ykf.entity.YkfDictDetailEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 客诉登记
 */
@RestController
@RequestMapping("/new/ykf/customer/complaint")
public class CustomerComplaintRegistrationController {

    @Autowired
    private CustomerComplaintRegistrationService customerComplaintRegistrationService;

    @Autowired
    private DictDetailService dictDetailService;


    /**
     * 获取投诉建议列表
     *
     * @return
     */
    @PostMapping("/getComplaintSuggestionsList")
    public R getComplaintSuggestionsList(@RequestBody ParamsModel<CustomerComplaintRegistrationEntity> params) {
        PageUtils page = customerComplaintRegistrationService.getComplaintSuggestionsList(params);
        return R.ok(page);
    }

    /**
     * 根据id查询建议
     *
     * @param map
     * @return
     */
    @PostMapping("/getComplaintSuggestion")
    public R getComplaintSuggestion(@RequestBody Map map) {
        Long complaintId = Long.parseLong(map.get("complaintId").toString());
        CustomerComplaintRegistrationEntity customerComplaintRegistrationEntity = customerComplaintRegistrationService.getById(complaintId);
        return R.ok(customerComplaintRegistrationEntity);
    }

    /**
     * 添加投诉建议
     */
    @PostMapping("/addComplaintSuggestion")
    public R addComplaintSuggestions(@RequestBody CustomerComplaintRegistrationEntity entity) {
        return customerComplaintRegistrationService.addComplaintSuggestions(entity);

    }

    /**
     * 编辑投诉建议
     */
    @PostMapping("/editComplaintSuggestion")
    public R editComplaintSuggestions(@RequestBody CustomerComplaintRegistrationEntity entity) {
        return customerComplaintRegistrationService.editCustomerComplaintRegistrationEntity(entity);
    }

    /**
     * 查询业务分部二
     */
    @PostMapping("/parentId")
    public R getDetailId(@RequestBody Map map) {
        Long parentId = Long.parseLong(map.get("parentId").toString());
        List<YkfDictDetailEntity> EntitryList = dictDetailService.getByParentIdList(parentId);
        System.out.println(EntitryList);
        return R.ok(EntitryList);
    }

    @PostMapping("/fileUpload")
    public R getUpload(@RequestParam("tsqd") String tsqd,
                       @RequestParam("tskhdjqd") String tskhdjqd,
                       @RequestParam("tswtfssj") String tswtfssj,
                       @RequestParam("tskhdjqm") String tskhdjqm,
                       @RequestParam("wgwtfby") String wgwtfby,
                       @RequestParam("wgwtfbe") String wgwtfbe,
                       @RequestParam("zdclry") String zdclry,
                       @RequestParam("gjc") String gjc,
                       @RequestParam("wtms") String wtms,
                       @RequestParam(name = "files",required = false) MultipartFile[] files) throws ParseException, IOException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");

        Date tswtfssjTime = sdf.parse(tswtfssj);

        return customerComplaintRegistrationService.saved(tsqd, tskhdjqd, tswtfssjTime, tskhdjqm, wgwtfby, wgwtfbe, zdclry, gjc, wtms, files);

    }

}
